/**
 * Created by jt on 2017/5/6.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";

jQuery(function () {
    App.init();
    var token = sessionStorage.getItem('token');
    if (token == null || token =='') {
        location.href = HOST_FRT+'/logins/login.html';
    }

    jQuery('.logOut').attr('href','../logins/login.html');
    var projId = getArgs().id;
    
    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/xjProjMngForPchs/getQotInf/'+projId,
        type: 'get',
        dataType: 'json',
        contentType:"application/json",
        headers: {
            'access_token': token,'login_type':'ums'
        },
        success: function(resp){
            if (!resp.success) {
                alert(resp.msgCod+' '+resp.msgInf);
                return;
            }
            console.log(resp)
            var servPrms='',qotMemo='';
            if (resp.data.qotInf != null && resp.data.qotInf != ''){
                if(resp.data.qotInf.servPrms != null) {
                    servPrms =resp.data.qotInf.servPrms;
                }
                if(resp.data.qotInf.qotMemo != null) {
                    qotMemo =resp.data.qotInf.qotMemo;
                }
            }
            $(".servPrms").html(servPrms);
            $(".qotMemo").html(qotMemo);

            if(resp.data.qotDtls !=null){
                for(var i = 0;i< resp.data.qotDtls.length;i++) {

                    var price = '报价已加密',matBnd = '';
                    if (resp.data.qotDtls[i].untPri != null) {
                        price = resp.data.qotDtls[i].untPri;
                    }
                    if(resp.data.qotDtls[i].matBnd != null){
                        matBnd = resp.data.qotDtls[i].matBnd;
                    }
                    resp.data.qotDtls[i].matBnd = resp.da
                    jQuery('.qotDtls').append('<tr>' +
                        '<td>'+resp.data.qotDtls[i].matNam+'</td> ' +
                        '<td>'+resp.data.qotDtls[i].matUnt+'</td> ' +
                        '<td>'+resp.data.qotDtls[i].splNum+'</td> ' +
                        '<td>'+resp.data.qotDtls[i].dlvAdr+'</td> ' +
                        '<td>'+resp.data.qotDtls[i].dlvDte+'</td> ' +
                        '<td>'+price+'</td> '+
                        '<td>'+resp.data.qotDtls[i].currTyp+'</td> ' +
                        '<td>'+matBnd+'</td></tr>');
                }

                if(resp.data.qotDtls[0].untPri != null){ // 已开标
                    var atches = resp.data.atches;
                    if ((atches!=null && atches!='undefined') && atches.length > 0){
                        for (var i= 0;i<atches.length;i++) {
                            jQuery('#tab_3').append('<div class="controls atchDiv"><span src="'+atches[i].atchUrl+'">'+atches[i].atchNam+'</span>' +
                                '&emsp;<a target="_blank" href="'+HOST_FILE+atches[i].atchUrl+'">查看</a></div>');
                        }
                    }
                }
            }
        },
        error:function(err){
            console.log(err);
        }
    });
});